window.addEventListener('load', function () {
    //渲染用户基本信息
    obj.type = 'get'
    obj.url = '/my/userinfo'
    obj.success = function (res) {
        render(res.data)
    }
    progress && progress.remove()
    function render(data) {
        let str = data.nickname || data.username
        welcome.innerHTML = '欢迎&nbsp;&nbsp;' + str
        if (data.user_pic !== null) {
            document.querySelectorAll('.userinfo>img').forEach(item => {
                item.src = decodeURIComponent(data.user_pic)
            })
            document.querySelectorAll('.userinfo>.text-avatar').forEach(item => item.style.display = "none")
        } else {
            document.querySelectorAll('.userinfo>.text-avatar').forEach(item => item.innerHTML = str[0])
            document.querySelectorAll('.userinfo>img').forEach(item => item.style.display = "none")
        }
    }
    myAxios(obj);
    //退出操作，弹出确认提示框，清空本地存储，回到登录界面
    btnLogout.addEventListener('click', function () {
        layer.confirm('确认退出?', { icon: 3, title: '提示' }, function (index) {
            localStorage.removeItem('mima')
            window.location.assign('/login.html')
            layer.close(index);
        });
    })
})